
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8"></meta>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
      <title>7.4.&nbsp;Import CSV - Chapter&nbsp;7.&nbsp;Export / Import</title>
      <link rel="stylesheet" type="text/css" href="../../docbook.css"></link>
      <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/chunked-base.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/extra.css"></link><script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script><script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js" type="text/javascript"></script><script src="../../javascript/datatable.js" type="text/javascript"></script><script src="../../javascript/colorize.js" type="text/javascript"></script><script src="../../javascript/tabs-for-chunked.js" type="text/javascript"></script><script src="../../javascript/mp-nav.js" type="text/javascript"></script><script src="../../javascript/versionswitcher.js" type="text/javascript"></script><script src="../../javascript/version.js" type="text/javascript"></script><script src="//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js" type="text/javascript"></script><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></meta>
      <link rel="prev" href="../load-csv/" title="7.3.&nbsp;Load CSV"></link>
      <link rel="next" href="../load-xls/" title="7.5.&nbsp;Loading Excel (XLS)"></link>
      <link rel="shortcut icon" href="https://neo4j.com/wp-content/themes/neo4jweb/favicon.ico"></link><script>
        $(document).ready(function() {
          CodeMirror.colorize();
          tabTheSource($('body'));
          var $header = $('header').first();
          $header.prepend(
            $('<a href="" id="logo"><img src="https://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-logo-2015.png" alt="Neo4j Logo"></img></a>')
          );
          var $sidebar = $('<div id="sidebar-wrapper"></div>');
          $.get('toc.html', function (d){
            $(d).appendTo($sidebar);
            highlightToc();
            highlightLibraryHeader();
          });
          $sidebar.insertAfter($('header').first());
        });
        </script></head>
   <body>
      <header>
         <div class="searchbox">
            <form id="search-form" class="search" name="search-form" role="search"><input id="search-form-input" name="q" title="search" type="search" lang="en" placeholder="Search Neo4j docs..." aria-label="Search Neo4j documentation" max-length="128" required="required"></input><input id="search-form-button" type="submit" value="Search"></input></form>
         </div>
         <ul class="documentation-library">
            <li><a href="https://neo4j.com/docs/operations-manual/current">Operations Manual</a></li>
            <li><a href="https://neo4j.com/docs/developer-manual/current/">Developer Manual</a></li>
            <li><a href="https://neo4j.com/docs/ogm-manual/current/">OGM Manual</a></li>
            <li><a href="https://neo4j.com/docs/graph-algorithms/current/">Graph Algorithms</a></li>
            <li><a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/">APOC</a></li>
            <li><a href="https://neo4j.com/docs/java-reference/current/">Java Reference</a></li>
         </ul>
         <nav id="header-nav"><span class="nav-previous"><a accesskey="p" href="../load-csv/"><span class="fa fa-long-arrow-left" aria-hidden="true"></span>Load CSV</a></span><span class="nav-current">
               <p class="nav-title hidden">7.4.&nbsp;Import CSV</p></span><span class="nav-next"><a accesskey="n" href="../load-xls/">Loading Excel (XLS)<span class="fa fa-long-arrow-right" aria-hidden="true"></span></a></span></nav>
      </header>
      <div id="search-results" class="hidden"></div>
      <section class="section" id="import-csv">
         <div class="titlepage">
            <div>
               <div>
                  <h2 class="title" style="clear: both"><a class="anchor" href="#import-csv"></a>7.4.&nbsp;Import CSV
                  </h2>
               </div>
            </div>
         </div>
         <p>CSV files that comply with the <a class="link" href="https://neo4j.com/docs/operations-manual/current/tools/import/file-header-format/" target="_top">Neo4j import tool&#8217;s header format</a> can be imported using the <code class="literal">apoc.import.csv</code> procedure. This procedure is intended to load small- to medium-sized data sets in an online database. For importing larger
            data sets, it is recommended to perform a batch import using the (<a class="link" href="https://neo4j.com/docs/operations-manual/current/tools/import/" target="_top">import tool</a>, which loads data in bulk to an offline (initially empty) database.
         </p>
         <section class="section" id="_usage">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_usage"></a>7.4.1.&nbsp;Usage
                     </h3>
                  </div>
               </div>
            </div>
            <p>The parameters of the <code class="literal">apoc.import.csv(&lt;nodes&gt;, &lt;relationships&gt;, &lt;config&gt;)</code> procedure are as follows.
            </p>
            <p>The <code class="literal">&lt;nodes&gt;</code> parameter is a list, where each element is a map defining a source file (<code class="literal">fileName</code>) to be loaded with a set of labels (<code class="literal">labels</code>):
            </p>
            <div class="informaltable">
               <div class="table" id="d0e6601">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                        <col class="col_3"></col>
                     </colgroup>
                     <thead>
                        <tr>
                           <th style="text-align: left; vertical-align: top; ">name</th>
                           <th style="text-align: left; vertical-align: top; ">description</th>
                           <th style="text-align: left; vertical-align: top; ">example</th>
                        </tr>
                     </thead>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">fileName</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>filename</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">'file:/students.csv'</code></p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">labels</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>set of labels</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">['Person', 'Student']</code></p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
            <p>The <code class="literal">&lt;relationships&gt;</code> parameter is also a list, where each element is a map defining a source file (<code class="literal">fileName</code>) to be loaded with a given relationship type (<code class="literal">type</code>):
            </p>
            <div class="informaltable">
               <div class="table" id="d0e6650">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                        <col class="col_3"></col>
                     </colgroup>
                     <thead>
                        <tr>
                           <th style="text-align: left; vertical-align: top; ">name</th>
                           <th style="text-align: left; vertical-align: top; ">description</th>
                           <th style="text-align: left; vertical-align: top; ">example</th>
                        </tr>
                     </thead>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">fileName</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>filename</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">'file:/works_at.csv'</code></p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">type</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>relationship type</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">'WORKS_AT'</code></p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
            <p>The <code class="literal">&lt;config&gt;</code> parameter is a map
            </p>
            <div class="informaltable">
               <div class="table" id="d0e6693">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                        <col class="col_3"></col>
                        <col class="col_4"></col>
                     </colgroup>
                     <thead>
                        <tr>
                           <th style="text-align: left; vertical-align: top; ">name</th>
                           <th style="text-align: left; vertical-align: top; ">description</th>
                           <th style="text-align: left; vertical-align: top; ">default</th>
                           <th style="text-align: left; vertical-align: top; "><a class="link" href="https://neo4j.com/docs/operations-manual/current/tools/import/options/" target="_top">import tool counterpart</a></th>
                        </tr>
                     </thead>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">delimiter</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>delimiter character between columns</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">,</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">--delimiter=,</code></p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">arrayDelimiter</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>delimiter character in arrays</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">;</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">--array-delimiter=;</code></p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">ignoreDuplicateNodes</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>for duplicate nodes, only load the first one and skip the rest (true) or fail the import (false)</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">false</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">--ignore-duplicate-nodes=false</code></p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">quotationCharacter</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>quotation character</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">"</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">--quote='"'</code></p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">stringIds</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>treat ids as strings</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">true</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">--id-type=STRING</code></p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">skipLines</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>lines to skip (incl. header)</p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">1</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">N/A</code></p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
         </section>
         <section class="section" id="_examples_for_apoc_import_csv">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_examples_for_apoc_import_csv"></a>7.4.2.&nbsp;Examples for apoc.import.csv
                     </h3>
                  </div>
               </div>
            </div>
            <section class="section" id="_loading_nodes">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_loading_nodes"></a>7.4.2.1.&nbsp;Loading nodes
                        </h4>
                     </div>
                  </div>
               </div>
               <p>Given the following CSV file and procedure call, the database loads two <code class="literal">Person</code> nodes with their <code class="literal">name</code> properties set:
               </p>
               <p><span class="formalpara-title">persons.csv.&nbsp;</span>
                  
               </p><pre class="screen highlight"><code>name:STRING
John
Jane</code></pre><p>
                  
               </p><pre class="programlisting highlight"><code data-lang="cypher">CALL apoc.import.csv([{fileName: 'file:/persons.csv', labels: ['Person']}], [], {})</code></pre></section>
            <section class="section" id="_loading_nodes_and_relationships">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_loading_nodes_and_relationships"></a>7.4.2.2.&nbsp;Loading nodes and relationships
                        </h4>
                     </div>
                  </div>
               </div>
               <p>Given the following CSV files and procedure call, the database loads two <code class="literal">Person</code> nodes and a <code class="literal">KNOWS</code> relationship between them (with the value of the <code class="literal">since</code> property set). Note that both the field terminators and the array delimiters are changed from the default value, and the
                  CSVs use numeric ids.
               </p>
               <p><span class="formalpara-title">persons.csv.&nbsp;</span>
                  
               </p><pre class="screen highlight"><code>:ID|name:STRING|speaks:STRING[]
1|John|en,fr
2|Jane|en,de</code></pre><p>
                  
               </p>
               <p><span class="formalpara-title">knows.csv.&nbsp;</span>
                  
               </p><pre class="screen highlight"><code>:START_ID|:END_ID|since:INT
1|2|2016</code></pre><p>
                  
               </p><pre class="programlisting highlight"><code data-lang="cypher">CALL apoc.import.csv(
  [{fileName: 'file:/persons.csv', labels: ['Person']}],
  [{fileName: 'file:/knows.csv', type: 'KNOWS'}],
  {delimiter: '|', arrayDelimiter: ',', stringIds: false}
)</code></pre><p>The loader supports advanced features of the import tool:</p>
               <div class="itemizedlist">
                  <ul class="itemizedlist" style="list-style-type: disc; ">
                     <li class="listitem"><span class="emphasis"><em>ID spaces</em></span> are supported, using the <a class="link" href="https://neo4j.com/docs/operations-manual/current/tools/import/file-header-format/#import-tool-id-spaces" target="_top">import tool&#8217;s syntax</a>.
                     </li>
                     <li class="listitem">Node labels can be specified with the <a class="link" href="https://neo4j.com/docs/operations-manual/current/tools/import/file-header-format/#import-tool-header-format-nodes" target="_top"><code class="literal">:LABEL</code></a> field.
                     </li>
                     <li class="listitem">Relationship types can be specified with the <a class="link" href="https://neo4j.com/docs/operations-manual/current/tools/import/file-header-format/#import-tool-header-format-rels" target="_top"><code class="literal">:TYPE</code></a> field.
                     </li>
                  </ul>
               </div>
            </section>
         </section>
      </section>
      <footer><script type="text/javascript">
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
          //Allow Linker
          ga('create', 'UA-1192232-34','auto', {'allowLinker': true});
          ga('send', 'pageview');
          // Load the plugin.
          ga('require', 'linker');
          // Define which domains to autoLink.
          ga('linker:autoLink', ['neo4j.org','neo4j.com','neotechnology.com','graphdatabases.com','graphconnect.com']);
        </script><script type="text/javascript">
          document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script>Munchkin.init('773-GON-065');</script></footer>
   </body>
</html>